package com.student.service.impl;

import com.student.mapper.RoomMapper;
import com.student.model.Room;
import com.student.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoomServiceImpl implements RoomService {
    @Autowired//自动注入
    private RoomMapper roomMapper;

    @Override
    public Room getInforById(Integer roomId) {
        Room room = roomMapper.getInforById(roomId);
        return room;
    }

    @Override
    public int insertRoom(Room room) {
        int count = roomMapper.insertRoom(room);
        return count;
    }

    @Override
    public int deleteInforById(Integer roomId) {
        int count = roomMapper.deleteInforById(roomId);
        return count;
    }

    @Override
    public List<Room> getAllRooms() {
        return roomMapper.getAllRoom();
    }

    @Override
    public int putRoomInfo(Room room) {
        int count = roomMapper.putRoomInfo(room);
        return count;
    }

    @Override
    public int insertBatchRoom(List<Room> rooms) {
        int count = 0;
        if(rooms != null && rooms.size() > 0){
            for(Room room : rooms){
                if(room != null){
                    int c = roomMapper.insertRoom(room);
                    count += c;
                }
            }
        }
        return count;
    }

    @Override
    public int deleteBathRoom(List<Integer> roomIds) {
        int count = 0;
        if(roomIds != null && roomIds.size() > 0){
            for(Integer roomId : roomIds){
                //查看是否有该房间
                Room room = roomMapper.getInforById(roomId);
                if(roomId != null){
                    int c = roomMapper.deleteRoom(roomId);
                    count += c;
                }
            }
        }
        return count;
    }

    @Override
    public List<Room> getRoomIncludeStudentInfoById(Integer roomId) {
        return roomMapper.getRoomIncludeStudentInfoById(roomId);
    }
}
